﻿namespace WMS6.SQLServerDAL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using System.Data.SqlClient;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.QueryEntity;

    public class LoadPickDetailDA : ILoadPickDetailDA
    {
        private string CREATED_BY = "@CREATED_BY";
        private string LINE_ID = "@LINE_ID";
        private string LOAD_ID = "@LOAD_ID";
        private string PICK_DETAIL_ID = "@PICK_DETAIL_ID";
        private string SQL_CHECK_LOAD_PICK_DETAIL_ID_UNIQUE = " SELECT COUNT(1) FROM @_@LOAD_PICK_DETAIL WHERE LOAD_ID = @LOAD_ID AND LINE_ID = @LINE_ID ";
        private string SQL_DELETE_LOAD_PICK_DETAIL = " DELETE FROM @_@LOAD_PICK_DETAIL WHERE LOAD_ID = @LOAD_ID AND LINE_ID = @LINE_ID ";
        private string SQL_DELETE_LOAD_PICK_DETAIL_BY_LOADID = " DELETE FROM @_@LOAD_PICK_DETAIL WHERE LOAD_ID = @LOAD_ID ";
        private string SQL_INSERT_LOAD_PICK_DETAIL = " INSERT INTO @_@LOAD_PICK_DETAIL ( WH_ID, LOAD_ID, LINE_ID, PICK_DETAIL_ID, STATUS, CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE) VALUES ( @WH_ID, @LOAD_ID, @LINE_ID, @PICK_DETAIL_ID, @STATUS, @CREATED_BY, GETDATE(), @UPDATED_BY, GETDATE() )  ";
        private string SQL_SELECT_ALL_LOAD_PICK_DETAIL = " SELECT LPD.ROWID, LPD.WH_ID, LPD.LOAD_ID, LPD.LINE_ID, LPD.PICK_DETAIL_ID, LPD.STATUS, LPD.CREATED_BY, LPD.CREATED_DATE, LPD.UPDATED_BY, LPD.UPDATED_DATE,PD.OWNER_ID,PD.SKU_ID,PD.ORDER_ID,PD.ORDER_LINE_ID,PD.LOT,PD.TO_LOC,PD.LPN_ID,PD.QTY  FROM @_@LOAD_PICK_DETAIL LPD  LEFT JOIN @_@PICK_DETAIL PD ON LPD.PICK_DETAIL_ID = PD.PICK_DETAIL_ID";
        private string SQL_SELECT_LOAD_PICK_DETAIL_MAX_LINEID = " SELECT ISNULL(MAX(LINE_ID),0) AS LINE_ID FROM @_@LOAD_PICK_DETAIL WHERE LOAD_ID = @LOAD_ID ";
        private string SQL_UPDATE_LOAD_PICK_DETAIL = " UPDATE @_@LOAD_PICK_DETAIL SET WH_ID = @WH_ID, PICK_DETAIL_ID = @PICK_DETAIL_ID, STATUS = @STATUS, UPDATED_BY = @UPDATED_BY, UPDATED_DATE = GETDATE() WHERE LOAD_ID = @LOAD_ID AND LINE_ID = @LINE_ID  ";
        private string SQL_UPDATE_LOAD_PICK_DETAIL_STATUS_BY_LOADID = " UPDATE @_@LOAD_PICK_DETAIL SET STATUS = @STATUS,UPDATED_BY = @UPDATED_BY,UPDATED_DATE = GETDATE() WHERE LOAD_ID = @LOAD_ID ";
        private string STATUS = "@STATUS";
        private string UPDATED_BY = "@UPDATED_BY";
        private string WH_ID = "@WH_ID";

        public bool CheckLoadPickDetailIDUnique(string loadID, int lineID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LOAD_ID", loadID), new SqlParameter("@LINE_ID", lineID) };
            return (DBHelper.ExecuteScalar(CommandType.Text, this.SQL_CHECK_LOAD_PICK_DETAIL_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public bool CheckLoadPickDetailIDUnique(DataBase dataBase, DbTransaction tran, string loadID, int lineID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LOAD_ID", loadID), new SqlParameter("@LINE_ID", lineID) };
            return (dataBase.ExecuteScalar(tran, CommandType.Text, this.SQL_CHECK_LOAD_PICK_DETAIL_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public int DeleteLoadPickDetail(List<string> loadID, List<string> whLoginID)
        {
            int result = 0;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    for (int j = 0; j < loadID.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LOAD_ID", loadID[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_LOAD_PICK_DETAIL_BY_LOADID.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int DeleteLoadPickDetail(List<string> loadID, List<string> lineID, List<string> whLoginID)
        {
            int result = 0;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    for (int j = 0; j < loadID.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LOAD_ID", loadID[j]), new SqlParameter("@LINE_ID", lineID[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_LOAD_PICK_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int DeleteLoadPickDetail(DataBase dataBase, DbTransaction tran, List<string> loadID, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    for (int j = 0; j < loadID.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LOAD_ID", loadID[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_LOAD_PICK_DETAIL_BY_LOADID.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public int DeleteLoadPickDetail(DataBase dataBase, DbTransaction tran, List<string> loadID, List<string> lineID, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    for (int j = 0; j < loadID.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LOAD_ID", loadID[j]), new SqlParameter("@LINE_ID", lineID[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_LOAD_PICK_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public DataSet GetAllLoadPickDetail(string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_LOAD_PICK_DETAIL.Replace("@_@", whLoginID);
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetAllLoadPickDetail(DataBase dataBase, DbTransaction tran, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_LOAD_PICK_DETAIL.Replace("@_@", whLoginID);
            return dataBase.ExecuteDataSet(tran, CommandType.Text, sql);
        }

        public List<LoadPickDetailInfo> GetLoadPickDetailByID(string loadID, string whLoginID)
        {
            List<LoadPickDetailInfo> loadPickDetailInfoList = new List<LoadPickDetailInfo>();
            string sql = this.SQL_SELECT_ALL_LOAD_PICK_DETAIL.Replace("@_@", whLoginID) + " WHERE LPD.LOAD_ID = @LOAD_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LOAD_ID", loadID) };
            LoadPickDetailInfo loadPickDetailInfo = null;
            using (IDataReader reader = DBHelper.ExecuteReader(CommandType.Text, sql, paras))
            {
                while (reader.Read())
                {
                    DateTime CS00002;
                    loadPickDetailInfo = new LoadPickDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["LOAD_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, reader["PICK_DETAIL_ID"].ToString(), reader["STATUS"].ToString(), reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : (CS00002 = new DateTime()), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : (CS00002 = new DateTime()), reader["OWNER_ID"].ToString(), reader["SKU_ID"].ToString(), reader["ORDER_ID"].ToString(), reader["ORDER_LINE_ID"].ToString(), reader["LOT"].ToString(), reader["TO_LOC"].ToString(), reader["LPN_ID"].ToString(), (reader["QTY"].ToString() != "") ? decimal.Parse(reader["QTY"].ToString()) : 0M);
                    loadPickDetailInfoList.Add(loadPickDetailInfo);
                }
            }
            return loadPickDetailInfoList;
        }

        public LoadPickDetailInfo GetLoadPickDetailByID(string loadID, int lineID, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_LOAD_PICK_DETAIL.Replace("@_@", whLoginID) + " WHERE LPD.LOAD_ID = @LOAD_ID AND LPD.LINE_ID = @LINE_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LOAD_ID", loadID), new SqlParameter("@LINE_ID", lineID) };
            LoadPickDetailInfo loadPickDetailInfo = null;
            using (IDataReader reader = DBHelper.ExecuteReader(CommandType.Text, sql, paras))
            {
                if (reader.Read())
                {
                    loadPickDetailInfo = new LoadPickDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["LOAD_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, reader["PICK_DETAIL_ID"].ToString(), reader["STATUS"].ToString(), reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime(), reader["OWNER_ID"].ToString(), reader["SKU_ID"].ToString(), reader["ORDER_ID"].ToString(), reader["ORDER_LINE_ID"].ToString(), reader["LOT"].ToString(), reader["TO_LOC"].ToString(), reader["LPN_ID"].ToString(), (reader["QTY"].ToString() != "") ? decimal.Parse(reader["QTY"].ToString()) : 0M);
                }
            }
            return loadPickDetailInfo;
        }

        public List<LoadPickDetailInfo> GetLoadPickDetailByID(DataBase dataBase, DbTransaction tran, string loadID, string whLoginID)
        {
            List<LoadPickDetailInfo> loadPickDetailInfoList = new List<LoadPickDetailInfo>();
            string sql = this.SQL_SELECT_ALL_LOAD_PICK_DETAIL.Replace("@_@", whLoginID) + " WHERE LPD.LOAD_ID = @LOAD_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LOAD_ID", loadID) };
            LoadPickDetailInfo loadPickDetailInfo = null;
            IDataReader reader = dataBase.ExecuteReader(tran, CommandType.Text, sql, paras);
            while (reader.Read())
            {
                DateTime CS00002;
                loadPickDetailInfo = new LoadPickDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["LOAD_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, reader["PICK_DETAIL_ID"].ToString(), reader["STATUS"].ToString(), reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : (CS00002 = new DateTime()), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : (CS00002 = new DateTime()), reader["OWNER_ID"].ToString(), reader["SKU_ID"].ToString(), reader["ORDER_ID"].ToString(), reader["ORDER_LINE_ID"].ToString(), reader["LOT"].ToString(), reader["TO_LOC"].ToString(), reader["LPN_ID"].ToString(), (reader["QTY"].ToString() != "") ? decimal.Parse(reader["QTY"].ToString()) : 0M);
                loadPickDetailInfoList.Add(loadPickDetailInfo);
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            return loadPickDetailInfoList;
        }

        public LoadPickDetailInfo GetLoadPickDetailByID(DataBase dataBase, DbTransaction tran, string loadID, int lineID, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_LOAD_PICK_DETAIL.Replace("@_@", whLoginID) + " WHERE LPD.LOAD_ID = @LOAD_ID AND LPD.LINE_ID = @LINE_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LOAD_ID", loadID), new SqlParameter("@LINE_ID", lineID) };
            LoadPickDetailInfo loadPickDetailInfo = null;
            IDataReader reader = dataBase.ExecuteReader(tran, CommandType.Text, sql, paras);
            if (reader.Read())
            {
                loadPickDetailInfo = new LoadPickDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["LOAD_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, reader["PICK_DETAIL_ID"].ToString(), reader["STATUS"].ToString(), reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime(), reader["OWNER_ID"].ToString(), reader["SKU_ID"].ToString(), reader["ORDER_ID"].ToString(), reader["ORDER_LINE_ID"].ToString(), reader["LOT"].ToString(), reader["TO_LOC"].ToString(), reader["LPN_ID"].ToString(), (reader["QTY"].ToString() != "") ? decimal.Parse(reader["QTY"].ToString()) : 0M);
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            return loadPickDetailInfo;
        }

        public DataSet GetLoadPickDetailByQueryList(List<string> sqlWhere, LoadPickDetailQueryEntity loadpickdetailQuery, string whLoginID)
        {
            string temp = this.SQL_SELECT_ALL_LOAD_PICK_DETAIL.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!loadpickdetailQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, loadpickdetailQuery.CurrentPage, loadpickdetailQuery.PageSize, loadpickdetailQuery.SortField, loadpickdetailQuery.SortDirection);
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, temp);
        }

        public DataSet GetLoadPickDetailByQueryList(DataBase dataBase, DbTransaction tran, List<string> sqlWhere, LoadPickDetailQueryEntity loadpickdetailQuery, string whLoginID)
        {
            string temp = this.SQL_SELECT_ALL_LOAD_PICK_DETAIL.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            temp = PagingHelper.GetPagingSQL(temp, loadpickdetailQuery.CurrentPage, loadpickdetailQuery.PageSize, loadpickdetailQuery.SortField, loadpickdetailQuery.SortDirection);
            return dataBase.ExecuteDataSet(tran, CommandType.Text, temp);
        }

        public int GetLoadPickDetailMaxLineID(string loadID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LOAD_ID", loadID) };
            return int.Parse(DBHelper.ExecuteScalar(CommandType.Text, this.SQL_SELECT_LOAD_PICK_DETAIL_MAX_LINEID.Replace("@_@", whLoginID), paras).ToString());
        }

        public int GetLoadPickDetailMaxLineID(DataBase dataBase, DbTransaction tran, string loadID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LOAD_ID", loadID) };
            return int.Parse(dataBase.ExecuteScalar(tran, CommandType.Text, this.SQL_SELECT_LOAD_PICK_DETAIL_MAX_LINEID.Replace("@_@", whLoginID), paras).ToString());
        }

        public int InsertLoadPickDetail(LoadPickDetailInfo loadPickDetailInfo, List<string> whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    loadPickDetailInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_LoadPickDetail_Parameters(loadPickDetailInfo);
                    if (paras != null)
                    {
                        result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_LOAD_PICK_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int InsertLoadPickDetail(DataBase dataBase, DbTransaction tran, LoadPickDetailInfo loadPickDetailInfo, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    loadPickDetailInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_LoadPickDetail_Parameters(loadPickDetailInfo);
                    if (paras != null)
                    {
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_LOAD_PICK_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        private SqlParameter[] Set_LoadPickDetail_Parameters(LoadPickDetailInfo loadPickDetailInfo)
        {
            SqlParameter[] paramArray = new SqlParameter[] { new SqlParameter(this.WH_ID, SqlDbType.VarChar, 30), new SqlParameter(this.LOAD_ID, SqlDbType.VarChar, 20), new SqlParameter(this.LINE_ID, SqlDbType.Int, 4), new SqlParameter(this.PICK_DETAIL_ID, SqlDbType.VarChar, 20), new SqlParameter(this.STATUS, SqlDbType.VarChar, 20), new SqlParameter(this.CREATED_BY, SqlDbType.VarChar, 20), new SqlParameter(this.UPDATED_BY, SqlDbType.VarChar, 20) };
            if (!string.IsNullOrEmpty(loadPickDetailInfo.WhID))
            {
                paramArray[0].Value = loadPickDetailInfo.WhID;
            }
            else
            {
                paramArray[0].Value = DBNull.Value;
            }
            paramArray[1].Value = loadPickDetailInfo.LoadID;
            paramArray[2].Value = loadPickDetailInfo.LineID;
            paramArray[3].Value = loadPickDetailInfo.PickDetailID;
            paramArray[4].Value = loadPickDetailInfo.Status;
            paramArray[5].Value = loadPickDetailInfo.CreatedBy;
            paramArray[6].Value = loadPickDetailInfo.UpdatedBy;
            return paramArray;
        }

        public int UpdateLoadPickDetail(LoadPickDetailInfo loadPickDetailInfo, List<string> whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    loadPickDetailInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_LoadPickDetail_Parameters(loadPickDetailInfo);
                    if (paras != null)
                    {
                        result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_LOAD_PICK_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int UpdateLoadPickDetail(DataBase dataBase, DbTransaction tran, LoadPickDetailInfo loadPickDetailInfo, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    loadPickDetailInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_LoadPickDetail_Parameters(loadPickDetailInfo);
                    if (paras != null)
                    {
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_LOAD_PICK_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public int UpdateLoadPickDetailStatusByLoadID(string loadID, string status, string whLoginID, PubParasInfo pubParasInfo)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@STATUS", status), new SqlParameter("@UPDATED_BY", pubParasInfo.UserID), new SqlParameter("@LOAD_ID", loadID) };
                if (paras != null)
                {
                    result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_LOAD_PICK_DETAIL_STATUS_BY_LOADID.Replace("@_@", whLoginID), paras);
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int UpdateLoadPickDetailStatusByLoadID(DataBase dataBase, DbTransaction tran, string loadID, string status, string whLoginID, PubParasInfo pubParasInfo)
        {
            int result = 0;
            try
            {
                SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@STATUS", status), new SqlParameter("@UPDATED_BY", pubParasInfo.UserID), new SqlParameter("@LOAD_ID", loadID) };
                if (paras != null)
                {
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_LOAD_PICK_DETAIL_STATUS_BY_LOADID.Replace("@_@", whLoginID), paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }
    }
}

